<template>
  <div class="order-list">
    <el-card 
      v-for="order in orders" 
      :key="order.id" 
      class="order-card"
      shadow="hover"
      :body-style="{ padding: '0' }"
    >
      <div class="order-header">
        <span class="order-time">{{ order.purchaseTime }}</span>
        <span class="order-status">
          <el-tag :type="getStatusTagType(order.status)">
            {{ getStatusText(order.status) }}
          </el-tag>
        </span>
      </div>
      
      <div class="order-body">
        <div class="product-info">
          <img :src="order.productImage" class="product-image">
          <div class="product-details">
            <h4>{{ order.productTitle }}</h4>
            <p class="price">￥{{ order.price }}</p>
          </div>
        </div>
        
        <div class="seller-info">
          <el-avatar :src="order.sellerAvatar" size="small" />
          <span class="seller-name">{{ order.seller }}</span>
        </div>
      </div>
      
      <div class="order-footer">
        <el-button 
          v-if="order.status === 'pending-payment'" 
          type="primary" 
          size="small"
          @click="$emit('pay', order.id)"
        >
          去付款
        </el-button>
        
        <el-button 
          v-if="order.status === 'pending-receive'" 
          type="success" 
          size="small"
          @click="$emit('confirm', order.id)"
        >
          确认收货
        </el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  props: {
    orders: {
      type: Array,
      required: true
    }
  },
  setup() {
    const getStatusText = (status) => {
      const map = {
        'pending-payment': '待付款',
        'pending-receive': '待收货',
        'completed': '已完成'
      };
      return map[status] || status;
    };

    const getStatusTagType = (status) => {
      const map = {
        'pending-payment': 'warning',
        'pending-receive': '',
        'completed': 'success'
      };
      return map[status] || '';
    };

    return {
      getStatusText,
      getStatusTagType
    };
  }
}
</script>

<style scoped>
.order-card {
  margin-bottom: 20px;
}

.order-header {
  padding: 12px 15px;
  border-bottom: 1px solid #ebeef5;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.order-body {
  padding: 15px;
}

.product-info {
  display: flex;
  margin-bottom: 15px;
}

.product-image {
  width: 80px;
  height: 80px;
  object-fit: cover;
  margin-right: 15px;
  border-radius: 4px;
}

.product-details h4 {
  margin: 0 0 8px 0;
  color: #303133;
}

.product-details .price {
  color: #f56c6c;
  font-weight: bold;
}

.seller-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #606266;
  font-size: 13px;
}

.order-footer {
  padding: 0 15px 15px;
  text-align: right;
}
</style>